//Tuesday, March 16 2010, 08:53:28
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class ColorfulBoxesAndBalls
{
public:
	int getMaximum(int numRed, int numBlue, int onlyRed, int onlyBlue,
			int bothColors)
	{
		long long mmax = -200000;
		for (int i = 0; i <= numBlue; i++)
		{
			for (int j = 0; j <= numRed; j++)
			{
				if (numRed - j == numBlue - i)
				{
					mmax = max(mmax,(long long) i * onlyBlue + j * onlyRed + 2 * (numBlue
							- i) * bothColors);
				}
			}
		}
		return mmax;
	}
};
/*
 * You can also take one for to implement this by using both ones as the varaible.
 * */
